import os

class RunLocustMain:


    def case_for_run(self, param=None, file_path=None,run_name="debug"):
        if run_name == "debug":
            if param == None:
                os.system("locust -f {0} {1}".format(file_path,'--headless -u 1 -r 1 -t 30'))
            elif param == "log":
                os.system("locust -f {0} {1} --skip-log-setup".format(file_path, '--headless -u 2 -r 1 -t 40'))
        elif run_name == "webui":
            if param == None:
                os.system("locust -f {0}".format(file_path))
            elif param == "log":
                os.system("locust -f {0} --skip-log-setup".format(file_path))

        elif run_name =="master":
            # locust -f locustfile.py --master-port=5558 --web-port=8091 --skip-log-setup主机
            # locust --master  -f prometheus_exporter.py --web-port=8090  配置时序数据监听参数
            if param == None:
                os.system("locust --{0} -f {1}".format(run_name,file_path))
            elif param == "log":
                os.system("locust --{0} -f {1} --skip-log-setup".format(run_name, file_path))
            elif param == "web-port":
                os.system("locust --{0} -f {1} --{2} --skip-log-setup".format(run_name, file_path,param))
            elif param == "master-port":
                param == "master-port=5558"
                os.system("locust -f {0} --{1} --skip-log-setup".format(file_path, param))
        elif run_name == "worker":
            if param == None: #locust -f locustfile.py  --worker --master-host=192.168.10.158:5558 --skip-log-setup从机
                os.system("locust --{0} -f {1}".format(run_name, file_path))
            elif param == "log":
                os.system("locust --{0} -f {1} --skip-log-setup".format(run_name, file_path))
            elif param == "master-host":
                param == "master-host=192.168.10.158:5558"
                os.system("locust --{0} -f {1} --{2} --skip-log-setup".format(run_name, file_path,param))








runCase = RunLocustMain()

if __name__ == "__main__":
    run = RunLocustMain()
    # run.case_all()
    run.case_file('-s', '../')


